home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000173_icon-group-sender _Mon Aug 2 16:52:39 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA20277
  4.     for icon-group-addresses; Mon, 2 Aug 1999 16:50:42 -0700 (MST)
  5. Message-Id: <199908022350.QAA20277@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 3 Aug 1999 10:50:09 +1200 (NZST)
  7. From: "Richard A. O'Keefe" <ok@hermes.otago.ac.nz>
  8. To: gep2@terabites.com, icon-group@optima.CS.Arizona.EDU
  9. Subject: Re:  When Do You Keep A Quirk?
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13. It sounds as though the right thing to do is to withdraw the
  14. basename function *entirely*.
  15.  
  16. I'd like to point out that the situation in UNIX is actually
  17. rather confused, thanks to some people adding 'neat hacks'.
  18.  
  19. Solaris:
  20.     basename string [suffix]
  21.  
  22.     deletes any prefix ending in / (does that mean '/' or does it
  23.     mean _any_ directory separator?  matters on DOS/Windows/OS/2)
  24.  
  25.     suffix, if present, is a REGULAR EXPRESSION; if there is a
  26.     tail of string matching suffix, it will be removed (but if
  27.     there are _several_ such tails, _which_?)
  28.  
  29. XPG4, BSD
  30.     basename string [suffix]
  31.  
  32.     same rule and problem with string; but suffix is a LITERAL
  33.     and NONE of its characters are significant.  There is for
  34.     example nothing special about '.'.
  35.  
  36. C library:
  37.     basename(path)
  38.  
  39.     does NOT take a suffix argument; removes leading directory
  40.     prefixes by smashing its argument.  It also deletes any
  41.     trailing slashes, except that a path that is one or more
  42.     slashes and nothing else yields "/".  A null pointer or an
  43.     empty string yields ".".
  44.  
  45. In particular,
  46.     basename latex .tex
  47. could give you 'l' or 'latex' depending on which of
  48. /usr/bin /usr/xpg4/bin comes first in your $PATH.
  49.  
  50. The basename command combines two operations:
  51.     remove_directory_part
  52. which is what the basename() function does, and
  53.     remove_matching_extension
  54. which has no corresponding library function.  Nor is the function
  55. I've _really_ wanted often enough,
  56.     remove_any_extension
  57. provided in any form.
  58.  
  59. I firmly believe that the _best_ thing to do is to junk basename and
  60. its relatives completely and to provide a 'pathname' library modelled
  61. on Common Lisp.  The second best thing to do is to throw 'basename'
  62. out as being just too confusing, and to provide two _new_
  63. library functions
  64.  
  65.     remove_directory_part(FileName) ->
  66.         FileName without any (drive or) directory part.
  67.         name (if present), extension (if present), and
  68.         version number (if present) are retained.
  69.  
  70.     remove_extension(FileName[, Extension]) ->
  71.     if Extension is provided,
  72.        ignore any leading dot to get Extension',
  73.        remove trailing . Extension' from FileName if present,
  74.        no change to FileName if . Extension' not present
  75.     if Extension not provided,
  76.         remove trailing . ext from FileName if present,
  77.         where ext is anything host file system allows in an
  78.         extension.
  79.         Leave any directory part intact.
  80.     return modified FileName.
  81.  
  82. When writing new code, you can use these without wondering which
  83. version of `basename', if any, Icon `basename' corresponds to.
  84.  
  85. Old code will promptly break.  If it assumed the documented
  86. behavior of basename, just plug in
  87.     basename(F, E) = remove_extension(remove_directory_part(F), E)
  88.     basename(F)    = remove_directory_part(F)
  89.  
  90. If it assumed the actual behaviour, just plug in
  91.     basename(F) = remove_extension(remove_directory_part(F))
  92.  
  93. One of the best things about Java is @deprecated, obviously swiped
  94. from Eiffel's 'obsolete' keyword.  In Eiffel, you can write
  95.     <procedure heading>
  96.     obsolete "<string>"
  97.     <procedure body>
  98. and the compiler writes the string as a warning if your program uses
  99. that procedure.  Icon could do with something similar for cases like this.
  100.  
  101.